package daobeauty.interceptor.returntype.handler.impl;

import java.util.List;

import daobeauty.interceptor.returntype.handler.ReturnTypeHandler;

/**
 * ReturnTypeHandler for methods returning an Array of Objects (or any other object type).
 * 
 * @author M. Serhat Cinar
 *
 */
public class ArrayReturnType implements ReturnTypeHandler<Object[]> {

	/**
	 * Converts the given List to an Array of Objects.
	 * 
	 * @see daobeauty.interceptor.returntype.handler.ReturnTypeHandler#convert(java.util.List)
	 */
	@SuppressWarnings("unchecked")
	public Object[] convert(List result) {
		return result.toArray(new Object[result.size()]);
	}
	
	/**
	 * Creates a new Array of Objects with the given Object as only element.
	 * 
	 * @see daobeauty.interceptor.returntype.handler.ReturnTypeHandler#convert(java.lang.Object)
	 */
	public Object[] convert(Object result) {
		return new Object[]{result};
	}
}
